package com.leiduoduo.oms.service;

import com.leiduoduo.oms.dao.RestaurantDao;
import com.leiduoduo.oms.pojo.Restaurant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class RestaurantServiceIpml implements RestaurantService {
    @Autowired
    RestaurantDao restaurantDao;

    @Override
    public boolean addRestaurant(Restaurant restaurant) {
        restaurant.setCreated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))
                .setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return restaurantDao.addRestaurant(restaurant);
    }

    @Override
    public boolean delRestaurant(Restaurant restaurant) {
        restaurant.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return restaurantDao.delRestaurant(restaurant);
    }

    @Override
    public boolean upRestaurant(Restaurant restaurant) {
        restaurant.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return restaurantDao.upRestaurant(restaurant);
    }

    @Override
    public Restaurant getRestaurantById(int id) {
        return restaurantDao.getRestaurantById(id);
    }

    @Override
    public List<Restaurant> getRestaurantList() {
        return restaurantDao.getRestaurantList();
    }

    @Override
    public Restaurant getRestaurantByCode(String code) {
        return restaurantDao.getRestaurantByCode(code);
    }
}
